package com.example.hotelmanagement.service.impl;

import com.example.hotelmanagement.domain.entity.RoomGuest;
import com.example.hotelmanagement.mapper.RoomGuestMapper;
import com.example.hotelmanagement.service.RoomGuestService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (RoomGuest)表服务实现类
 *
 * @author makejava
 * @since 2023-06-10 17:32:51
 */
@Service("roomGuestService")
public class RoomGuestServiceImpl implements RoomGuestService {
    @Resource
    private RoomGuestMapper roomGuestMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public RoomGuest queryById(Long id) {
        return this.roomGuestMapper.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param roomGuest 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RoomGuest> queryByPage(RoomGuest roomGuest, PageRequest pageRequest) {
        long total = this.roomGuestMapper.count(roomGuest);
        return new PageImpl<>(this.roomGuestMapper.queryAllByLimit(roomGuest, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param roomGuest 实例对象
     * @return 实例对象
     */
    @Override
    public RoomGuest insert(RoomGuest roomGuest) {
        this.roomGuestMapper.insert(roomGuest);
        return roomGuest;
    }

    /**
     * 修改数据
     *
     * @param roomGuest 实例对象
     * @return 实例对象
     */
    @Override
    public RoomGuest update(RoomGuest roomGuest) {
        this.roomGuestMapper.update(roomGuest);
        return this.queryById(roomGuest.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.roomGuestMapper.deleteById(id) > 0;
    }
}
